package com.app.micaihu.view.army.presenter

import com.app.base.mvp.BasePresenter
import com.app.http.NetRequestListener
import com.app.http.bean.BaseBean
import com.app.micaihu.utils.ApiServiceUtils.apiService
import com.app.micaihu.utils.ParamsMapUtils
import com.app.micaihu.view.army.contract.ArmyCreateContract
import com.app.micaihu.view.bean.ArmyCreateInfo
import com.app.utils.biz.Biz

/**
 * 创建军团
 */
open class ArmyCreatePresenter : BasePresenter<ArmyCreateContract.View>(), ArmyCreateContract.Presenter {


    override fun createArmyIndex() {
        getView()?.showLoading()
        val params = ParamsMapUtils.commonParams
        params["uid"] = Biz.instance.uid()
        requestNetwork(apiService.armyCreateArmyIndex(params), object : NetRequestListener<BaseBean<ArmyCreateInfo?>?> {
            override fun onSuccess(result: BaseBean<ArmyCreateInfo?>?) {
                getView()?.hideLoading()
                getView()?.handleCreateArmyIndex(result)
            }

            override fun onFailed(e: Throwable?) {
                getView()?.hideLoading()
                getView()?.handleCreateArmyIndex(null)
                getView()?.onError(e)
            }
        })
    }

    override fun createArmy(armyIcon: String, armyName: String, tag: String, warZone: String, armyDesc: String) {
        getView()?.showLoading()
        val params = ParamsMapUtils.commonParams
        params["uid"] = Biz.instance.uid()
        params["armyIcon"] = armyIcon
        params["armyName"] = armyName
        params["tag"] = tag
        params["warZone"] = warZone
        params["armyDesc"] = armyDesc
        requestNetwork(apiService.createArmy(params), object : NetRequestListener<BaseBean<Any?>?> {
            override fun onSuccess(result: BaseBean<Any?>?) {
                getView()?.hideLoading()
                getView()?.handleCreateArmy(result)
            }

            override fun onFailed(e: Throwable?) {
                getView()?.hideLoading()
                getView()?.handleCreateArmy(null)
                getView()?.onError(e)
            }
        })
    }

    override fun editNotice(gid: String, content: String) {
        getView()?.showLoading()
        val params = ParamsMapUtils.commonParams
        params["uid"] = Biz.instance.uid()
        params["gid"] = gid
        params["content"] = content
        requestNetwork(apiService.editNotice(params), object : NetRequestListener<BaseBean<Any?>?> {
            override fun onSuccess(result: BaseBean<Any?>?) {
                getView()?.hideLoading()
                getView()?.handleEditNotice(result)
            }

            override fun onFailed(e: Throwable?) {
                getView()?.hideLoading()
                getView()?.handleEditNotice(null)
                getView()?.onError(e)
            }
        })
    }
}